package com.mobile.check.util;

import java.math.BigDecimal;

public class DoubleUtil {
    public static double getDouble(double initValue, int scale)  {
        try {
            BigDecimal bg = new BigDecimal(initValue);
            double result = bg.setScale(scale, BigDecimal.ROUND_HALF_UP).doubleValue();
            if (result > (int)result) {
                return result;
            }else{
                return (int)result;
            }

        } catch (Exception ex) {
            return 0d;
        }
    }

    public static double getDouble(String initValue, int scale) {
        try {
            BigDecimal bg = new BigDecimal(initValue);
            double result = bg.setScale(scale, BigDecimal.ROUND_HALF_UP).doubleValue();
            if (result > (int)result) {
                return result;
            }else{
                return (int)result;
            }
        } catch (Exception ex) {
            return 0d;
        }

    }
}
